package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.environment.domain.OpmEnvExhaustTest;
import com.ruoyi.environment.domain.OpmEnvRule;
import com.ruoyi.environment.mapper.OpmEnvExhaustTestMapper;
import com.ruoyi.environment.service.IOpmEnvExhaustTestService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 废气采集Service业务层处理
 *
 * @author zmc
 * @date 2021-07-23
 */
@Service
public class OpmEnvExhaustTestServiceImpl extends LinkFileServiceImpl implements IOpmEnvExhaustTestService {
    @Autowired
    private OpmEnvExhaustTestMapper opmEnvExhaustTestMapper;

    /**
     * 查询废气采集
     *
     * @param id 废气采集ID
     * @return 废气采集
     */
    @Override
    public OpmEnvExhaustTest selectOpmEnvExhaustTestById(Long id) {
        OpmEnvExhaustTest result = opmEnvExhaustTestMapper.selectOpmEnvExhaustTestById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询废气采集列表
     *
     * @param opmEnvExhaustTest 废气采集
     * @return 废气采集
     */
    @Override
    public List<OpmEnvExhaustTest> selectOpmEnvExhaustTestList(OpmEnvExhaustTest opmEnvExhaustTest) {
        return opmEnvExhaustTestMapper.selectOpmEnvExhaustTestList(opmEnvExhaustTest);
    }

    /**
     * 新增废气采集
     *
     * @param opmEnvExhaustTest 废气采集
     * @return 结果
     */
    @Override
    public int insertOpmEnvExhaustTest(OpmEnvExhaustTest opmEnvExhaustTest) {
        opmEnvExhaustTest.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvExhaustTest.setCreateTime(DateUtils.getNowDate());
        opmEnvExhaustTest.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvExhaustTest.getFileIdList(), opmEnvExhaustTest.getId().toString());
        return opmEnvExhaustTestMapper.insertOpmEnvExhaustTest(opmEnvExhaustTest);
    }

    /**
     * 修改废气采集
     *
     * @param opmEnvExhaustTest 废气采集
     * @return 结果
     */
    @Override
    public int updateOpmEnvExhaustTest(OpmEnvExhaustTest opmEnvExhaustTest) {
        opmEnvExhaustTest.setUpdateTime(DateUtils.getNowDate());
        opmEnvExhaustTest.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvExhaustTest.getFileIdList(),Long.toString(opmEnvExhaustTest.getId()));
        return opmEnvExhaustTestMapper.updateOpmEnvExhaustTest(opmEnvExhaustTest);
    }

    /**
     * 批量删除废气采集
     *
     * @param ids 需要删除的废气采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvExhaustTestByIds(Long[] ids) {
        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvExhaustTestMapper.deleteOpmEnvExhaustTestByIds(ids);
    }

    /**
     * 删除废气采集信息
     *
     * @param id 废气采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvExhaustTestById(Long id) {
        return opmEnvExhaustTestMapper.deleteOpmEnvExhaustTestById(id);
    }
}
